package com.resou.reader.mine.setting;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.button.MaterialButton;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.resou.reader.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

public class SignOutDialog extends DialogFragment {

    @BindView(R.id.cancel_btn)
    MaterialButton cancelBtn;
    @BindView(R.id.complete_btn)
    MaterialButton completeBtn;
    Unbinder unbinder;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_hit)
    TextView tvHit;

    public static SignOutDialog newInstance() {
        Bundle args = new Bundle();
        SignOutDialog fragment = new SignOutDialog();
        fragment.setArguments(args);
        return fragment;
    }

    OnSignOutInteractionListener mInteractionListener;

    public void setInteractionListener(OnSignOutInteractionListener interactionListener) {
        mInteractionListener = interactionListener;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.dialog_exit, container, false);
        unbinder = ButterKnife.bind(this, view);
        getDialog().setCanceledOnTouchOutside(false);
        Window window = getDialog().getWindow();
        window.requestFeature(Window.FEATURE_NO_TITLE);
        super.onActivityCreated(savedInstanceState);
        window.setBackgroundDrawableResource(R.drawable.bg_login_fragment);
        WindowManager.LayoutParams attr = window.getAttributes();
        attr.width = WindowManager.LayoutParams.WRAP_CONTENT;
        attr.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(attr);
        window.setWindowAnimations(R.style.LoginFragmentAnimation);
        tvTitle.setText("退出账号");
        tvHit.setText("您确定要退出账号吗");

        return view;
    }

    @OnClick({R.id.cancel_btn, R.id.complete_btn})
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.cancel_btn:
                mInteractionListener.onCancelClicked();
                break;
            case R.id.complete_btn:
                mInteractionListener.onCompleteClicked();
                break;
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    interface OnSignOutInteractionListener {
        void onCancelClicked();

        void onCompleteClicked();
    }
}
